package com.geekaca.d07.test_stream;

import java.util.Objects;

public class Student {
    private String name;
    private String ID;

    public Student(String name, String ID) {
        this.name = name;
        this.ID = ID;
    }

    public Student(String s) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", ID='" + ID + '\'' +
                '}';
    }

    @Override
    public int hashCode() {
//        return super.hashCode();
        //生成一个hash值,依赖当前对象的各个属性值, 组入在一起生成唯一的值
        return Objects.hash(name, ID);
    }

    @Override
    public boolean equals(Object obj) {
//        return obj.hashCode();
        if (this == obj) {
            return true; //自己与自己比较
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        Student stu = (Student) obj;
        return  this.name.equals((stu.getName())) && this.ID.equals(stu.getID());
//        return this.hashCode() == stu.hashCode();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }
}
